<template>

  <div>
    <el-form :inline="true" :model="appUserWallet" class="demo-form-inline"
      style="display: flex; flex-direction: column; width: auto; height:200px; overflow-x: auto;flex-wrap: wrap;">

      <el-form-item label="钻石余额">
        <el-input v-model="appUserWallet.diamondBalance" placeholder="砖石余额" disabled></el-input>
      </el-form-item>

      <el-form-item label="金币余额">
        <el-input v-model="appUserWallet.goldBalance" placeholder="金币余额" disabled></el-input>
      </el-form-item>

      <el-form-item label="充值总次">
        <el-input v-model="appUserWallet.chargeNum" placeholder="提现成功数" disabled></el-input>
      </el-form-item>

      <el-form-item label="充值总额">
        <el-input v-model="appUserWallet.chargeTotal" placeholder="充值总额" disabled></el-input>
      </el-form-item>
      <el-form-item label="提现次数">
        <el-input v-model="appUserWallet.withdrawNum" placeholder="提现次数" disabled></el-input>
      </el-form-item>
      <el-form-item label="提现总额">
        <el-input v-model="appUserWallet.withdrawTotal" placeholder="提现总额" disabled></el-input>
      </el-form-item>

    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:appUser:addWallet']"
        >修改用户余额</el-button>
      </el-col>
      <right-toolbar @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="appUserList">
<!--      <el-table-column label="操作类型" align="center" prop="handleType">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.pay_wallet_log_handle_type" :value="scope.row.handleType"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="金币" align="center" prop="gold"/>
      <el-table-column label="钻石" align="center" prop="diamond"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作人" align="center" prop="createBy"/>
      <el-table-column label="操作时间" align="center" prop="createTime"/>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
    <!-- 推送消息 -->
    <el-dialog title="操作用户钱包余额" :visible.sync="open" width="500px" append-to-body>

      <el-form :inline="true" :model="logBo" class="demo-form-inline">

<!--        <el-form-item label="操作类型" prop="handleType">-->
<!--          <el-select v-model="logBo.handleType" placeholder="请选择操作类型" clearable>-->
<!--            <el-option v-for="dict in dict.type.pay_wallet_log_handle_type" :key="dict.value" :label="dict.label" :value="dict.value"/>-->
<!--          </el-select>-->
<!--        </el-form-item>-->

        <el-form-item label="金币">
          <el-input-number v-model="logBo.gold" placeholder="请输入金币数量"
                    style="width: 217px;" min="0"/>
          &nbsp;
          <el-radio-group v-model="logBo.goldType">
            <el-radio label="0">增加</el-radio>
            <el-radio label="1">减少</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="钻石">
          <el-input-number v-model="logBo.diamond" placeholder="请输入钻石数量"
                    style="width: 217px;" min="0"/>
          &nbsp;
          <el-radio-group v-model="logBo.diamondType">
            <el-radio label="0">增加</el-radio>
            <el-radio label="1">减少</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="logBo.remark" placeholder="备注"
                    style="width: 217px;"/>
        </el-form-item>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="toSend">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>

    </el-dialog>
  </div>

</template>

<script>
  import {queryWalletLog, changeWallet} from "@/api/service/appUser/appUser";

  export default {
    dicts: ['pay_wallet_log_handle_type'],
    props: {
      appUserWallet: {

      },
      userId: {
        type: String,
        default: '-1'
      }
    },
    data() {
      return {
        src: "/400/400",
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 用户基本信息-扩展(存放一些不重要但是必要的信息)表格数据
        appUserList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        openDetail: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId: this.userId

        },
        logBo: {},
        open: false
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询某用户的钱包余额修改记录 */
      getList() {
        if (this.userId) {
          this.loading = true;
          this.queryParams.userId = this.userId;
          queryWalletLog(this.queryParams).then(response => {
            this.appUserList = response.rows;
            this.total = response.total;
            this.loading = false;
          });
        }
      },
      handleAdd(){
        this.open = true
      },
      toSend() {
        var gold = this.logBo.gold;
        if(gold != 0 && this.logBo.goldType){
          this.logBo.gold = this.logBo.goldType == 0 ? gold : -gold;
        } else {
          this.logBo.gold = 0;
        }
        var diamond = this.logBo.diamond;
        if(diamond != 0 && this.logBo.diamondType){
          this.logBo.diamond = this.logBo.diamondType == 0 ? diamond : -diamond;
        } else {
          this.logBo.diamond = 0;
        }
        this.logBo.userId = this.userId
        this.logBo.handleType = 0
        changeWallet(this.logBo).then(response => {
          this.getList();
          this.logBo = {}
          this.open = false;
        });
      },
      cancel() {
        this.logBo = {}
        this.open = false;
      },
    }
  }
</script>

<style>
</style>
